package com.av.android;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.widget.ListView;

public class ResultsActivity extends BaseActivity {
	ListView listView ;
	List<Report> reports;
	SearchActivity2 parent;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_results);
		parent = (SearchActivity2)getParent();
		listView= (ListView) findViewById(R.id.mylist);
		//		ReportAdapter adapter = new ReportAdapter(this,R.layout.report_row, reports);

		if(getIntent().hasExtra("myreports")){
			new Thread(new Runnable() {

				public void run() {
					showLoading("");
					// TODO Auto-generated method stub
					final List<Report> ownreports = Utils.getOwnReports(LoginActivity.user.getUser_id());
					runOnUiThread(new Runnable() {

						public void run() {
							refresh(ownreports);
							hideLoading();

						}
					});
				}
			}).start();

		}else if(getIntent().hasExtra("subscriptions")){
			new Thread(new Runnable() {

				public void run() {
					showLoading("");
					// TODO Auto-generated method stub
					final List<Report> subs = Utils.getSubscriptions(LoginActivity.user.getUser_id());
					runOnUiThread(new Runnable() {

						public void run() {
							refresh(subs);
							hideLoading();

						}
					});
				}
			}).start();

		}
		// Assign adapter to ListView
		//		listView.setAdapter(adapter);
	}
	public void refresh(List<Report> reports2) {
		// TODO Auto-generated method stub
		if(reports2!=null){
			ReportAdapter adapter = new ReportAdapter(this,R.layout.report_row, reports2);
			
			listView.setAdapter(adapter);
		}
	}



}
